package client.UI_stuff;

import com.google.gwt.user.client.ui.*;
import client.*;

/**
 * ContactWidget
 *
 * @author Masud Idris
 * @version 1.0
 * @since Dec 19, 2007, 2:08:08 PM
 */
public class ContactWidget extends Composite {
  private Grid contactGrid;

  /**
   * Constructor
   *
   * @param toBeDisplayed the contact to be displayed
   */
  public ContactWidget(Contact toBeDisplayed) {
    contactGrid = new Grid(4, 2);
    initWidget(contactGrid);

    setStyleName("contact-widget");
    setGridStyle();

    populateGrid(toBeDisplayed);
  }


  /**
   * Takes the content of the contact and used it to populate the contactGrid
   *
   * @param toBeDisplayed contact to be displayed
   */
  private void populateGrid(Contact toBeDisplayed) {
    String name    = toBeDisplayed.getName();
    String email   = toBeDisplayed.getEmail();
    String phone   = toBeDisplayed.getPhoneNumber();
    String address = toBeDisplayed.getAddress();

    // Display the contact name
    contactGrid.setWidget(0, 0, new HTML("Name:"));
    contactGrid.setWidget(0, 1, new HTML(name));

    // Display the contact email address
    contactGrid.setWidget(1, 0, new HTML("Email:"));
    contactGrid.setWidget(1, 1, new HTML(email));

    // Display the contact phone number
    contactGrid.setWidget(2, 0, new HTML("Phone:"));
    contactGrid.setWidget(2, 1, new HTML(phone));

    // Display the contact address
    contactGrid.setWidget(3, 0, new HTML("Address:"));
    contactGrid.setWidget(3, 1, new HTML(address));
  }


  /**
   * Sets the style names for the contactGrid
   */
  private void setGridStyle() {
    contactGrid.getCellFormatter().addStyleName(0, 1, "value-column");
    contactGrid.getCellFormatter().addStyleName(1, 1, "value-column");
    contactGrid.getCellFormatter().addStyleName(2, 1, "value-column");
    contactGrid.getCellFormatter().addStyleName(3, 1, "value-column");

    contactGrid.getCellFormatter().addStyleName(0, 0, "key-column");
    contactGrid.getCellFormatter().addStyleName(1, 0, "key-column");
    contactGrid.getCellFormatter().addStyleName(2, 0, "key-column");
    contactGrid.getCellFormatter().addStyleName(3, 0, "key-column");
  }

}//end class ContactWidget
